package com.ac.input.web.action.setting;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.caac.core.util.HttpUtils;
import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;
import com.ac.input.dao.ReportsDao;
import com.ac.input.web.form.DataSearchForm;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2004</p>
 * <p>Company: AgileCentury</p>
 * @author <a href="mailto:lianzs@tom.com">Lianzs</a>
 * @version 1.0
 */

public class DefOrderAction extends BaseAction {
    private static final String KEY_GROUP_NAME = "groupName";
    private static final String KEY_SEL_PROPS = "selProps";
    private static final String KEY_UNSEL_PROPS = "unselProps";

    protected ActionForward doExecute(ActionMapping mapping,
                                      BaseForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response) throws
            Exception {
        DataSearchForm myForm = (DataSearchForm) form;

        if (myForm.isFirst()) {
            String groupName = HttpUtils.getParameter(request, KEY_GROUP_NAME);
            myForm.setMendId(groupName);
            ReportsDao rpsDao = (ReportsDao)this.getBean("reportsDao");
            myForm.setRhid(rpsDao.getHndInpDefById(myForm.getMendId()));
            myForm.setFirst(false);
        }
        List selProps = myForm.getRhid().getOrderClass().getChildren();
        List unselProps = myForm.getRhid().getOrderClass().getDmUnList();

        HttpUtils.setAttribute(request, KEY_SEL_PROPS, selProps);
        HttpUtils.setAttribute(request, KEY_UNSEL_PROPS, unselProps);

        return forward(mapping);
    }
}
